using HeadspringExample.Infrastructure.DataAccess;
using HeadspringExample.IntegrationTests.Infrastructure;
using NUnit.Framework;
using StructureMap;
using WatiN.Core;

namespace HeadspringExample.UITests
{
    [TestFixture]
    public class WebTestBase : IntegrationTestBase
    {
        private IE _ie;

        [SetUp]
        public virtual void SetUp()
        {
            _ie = new IE("http://localhost:8084/");
        }

        [TearDown]
        public virtual void TearDown()
        {
            if (_ie != null)
            {
                _ie.Dispose();
                _ie = null;
            }
        }

        protected IE Browser
        {
            get { return _ie; }
        }

        protected virtual void NavigateLink(string rel)
        {
            Link link = Browser.Link(Find.By("rel", rel));

            link.Click();
        }

        protected virtual void VerifyLinkExists(string rel)
        {
            Link link = Browser.Link(Find.By("rel", rel));

            Assert.IsNotNull(link);
        }

        protected FluentForm<TForm> ForForm<TForm>()
        {
            return new FluentForm<TForm>(Browser);
        }

        protected FluentPage<T> ForPage<T>()
        {
            return new FluentPage<T>(Browser);
        }

        protected void CurrentPageShouldBe(string pageId)
        {
            Element element = Browser.Element("body", null);

            Assert.AreEqual(pageId, element.Id);
        }
    }
}